package org.accp.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.accp.dao.ComplaintDao;
import org.accp.dao.NoticeDao;
import org.accp.pojo.Complaint;
import org.accp.pojo.Industry;
import org.accp.pojo.Notice;
import org.accp.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@Controller
@RequestMapping("/notice")
@CrossOrigin("*")
public class NoticeController {
        @Autowired
        private NoticeDao noticeDao;

        public void setComplaintDao(ComplaintDao complaintDao) {
            this.noticeDao = noticeDao;
        }

        @RequestMapping("/list")
        @ResponseBody
        public ResponseResult<List<Notice>> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit, Notice condition) throws Exception {
            Page<Complaint> pager = PageHelper.startPage(page, limit);
            List<Complaint> list = noticeDao.getConditionList(condition);
            return new ResponseResult(pager.getTotal(),list);
    }

    @RequestMapping("/batchDelete")
    @ResponseBody
    public ResponseResult batchDelete(Integer[] id) throws Exception{
        noticeDao.batchDelete(id);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseResult delete(int id) throws Exception{
        noticeDao.delete(id);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/add")
    @ResponseBody
    public ResponseResult add(Notice notice) throws Exception{
        noticeDao.add(notice);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/update")
    @ResponseBody
    public ResponseResult update(Notice notice) throws Exception{
        noticeDao.update(notice);
        return ResponseResult.createSuccessResult();
    }
}
